package com.db;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import com.conf.OAConfig;

public class DBConnection {
	private String url = "";
	private String clsName = "";
	private String userName = "";
	private String passWord = "";
	private Connection dbConn = null;
	private String dbName = "";
	private String path;

	public DBConnection() {
		
	}

	public DBConnection(String clsName, String url, String userName,
			String passWord) {
		this.clsName = clsName;
		this.url = url;
		this.userName = userName;
		this.passWord = passWord;
	}

	public void setClsName(String clsName) {
		this.clsName = clsName;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
	
	public Connection getDefConn() {
		try {
			clsName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
			userName=OAConfig.oadb_user;
			passWord=OAConfig.oadb_pw;
			String connUrl = OAConfig.oadb_url;
			Class.forName(clsName);
			dbConn = DriverManager.getConnection(connUrl, userName, passWord);
			return dbConn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public Connection getHrConn() {
		try {
			clsName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
			userName=OAConfig.hrdb_user;
			passWord=OAConfig.hrdb_pw;
			String connUrl = OAConfig.hrdb_url;
			Class.forName(clsName);
			dbConn = DriverManager.getConnection(connUrl, userName, passWord);
			return dbConn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public Connection getConn() {
		try {
			Class.forName(clsName);
			dbConn = DriverManager.getConnection(url, userName, passWord);
			return dbConn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public Connection getConn(String clsName, String url, String userName,
			String passWord) {
		try {
			Class.forName(clsName);
			dbConn = DriverManager.getConnection(url, userName, passWord);
			return dbConn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	//协同办公 OA  ERP 财务软件 HR软件 软件集成
	public Connection getConn(String url, String userName, String passWord) {
		try {
			Class.forName(clsName);
			dbConn = DriverManager.getConnection(url, userName, passWord);
			return dbConn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
